{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import logging\n",
    "import warnings\n",
    "import pandas as pd\n",
    "\n",
    "# from prophet import Prophet\n",
    "from neuralprophet import NeuralProphet, set_log_level\n",
    "\n",
    "set_log_level(\"ERROR\")\n",
    "logging.getLogger(\"prophet\").setLevel(logging.ERROR)\n",
    "warnings.filterwarnings(\"ignore\")"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Migrating from Prophet to NeuralProphet\n",
    "Both the Prophet and the NeuralProphet model share the concept of decomposing a time series into it's components which allows a human to inspect and interprete the individual components of the forecast. Since NeuralProphet adds new functionality, its interface may differ in part. We provide a guide on migrating a Prophet application to NeuralProphet. In the following we will provide code snippets for the most common functionalities when migrating from Prophet."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(\"https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv\")"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Trend\n",
    "\n",
    "In both frameworks, the trend can be configured during the init of the forecaster object. Pay attention to that the naming of the attributes might be slightly different between the two (eg. `changepoint_range` vs. `changepoints_range`)\n",
    "\n",
    "```python\n",
    "# Prophet\n",
    "p = Prophet(growth=\"linear\", n_changepoints=10, changepoint_range=0.5)\n",
    "p.fit(df)\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a30fc8c870354dc1b1cf0f8400f04692",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Finding best initial lr:   0%|          | 0/236 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "67f210e3e6e9418f8ef42b7189aeb2e6",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Training: 0it [00:00, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MAE</th>\n",
       "      <th>RMSE</th>\n",
       "      <th>Loss</th>\n",
       "      <th>RegLoss</th>\n",
       "      <th>epoch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3.042294</td>\n",
       "      <td>3.721973</td>\n",
       "      <td>0.240254</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2.858650</td>\n",
       "      <td>3.499020</td>\n",
       "      <td>0.215928</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2.625173</td>\n",
       "      <td>3.210334</td>\n",
       "      <td>0.185687</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2.314021</td>\n",
       "      <td>2.830819</td>\n",
       "      <td>0.147598</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.925760</td>\n",
       "      <td>2.352080</td>\n",
       "      <td>0.104436</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>0.349472</td>\n",
       "      <td>0.489684</td>\n",
       "      <td>0.004930</td>\n",
       "      <td>0.0</td>\n",
       "      <td>137</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>138</th>\n",
       "      <td>0.349406</td>\n",
       "      <td>0.491695</td>\n",
       "      <td>0.004922</td>\n",
       "      <td>0.0</td>\n",
       "      <td>138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>139</th>\n",
       "      <td>0.349232</td>\n",
       "      <td>0.489923</td>\n",
       "      <td>0.004923</td>\n",
       "      <td>0.0</td>\n",
       "      <td>139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>140</th>\n",
       "      <td>0.349017</td>\n",
       "      <td>0.491898</td>\n",
       "      <td>0.004918</td>\n",
       "      <td>0.0</td>\n",
       "      <td>140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>141</th>\n",
       "      <td>0.348818</td>\n",
       "      <td>0.493281</td>\n",
       "      <td>0.004913</td>\n",
       "      <td>0.0</td>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>142 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          MAE      RMSE      Loss  RegLoss  epoch\n",
       "0    3.042294  3.721973  0.240254      0.0      0\n",
       "1    2.858650  3.499020  0.215928      0.0      1\n",
       "2    2.625173  3.210334  0.185687      0.0      2\n",
       "3    2.314021  2.830819  0.147598      0.0      3\n",
       "4    1.925760  2.352080  0.104436      0.0      4\n",
       "..        ...       ...       ...      ...    ...\n",
       "137  0.349472  0.489684  0.004930      0.0    137\n",
       "138  0.349406  0.491695  0.004922      0.0    138\n",
       "139  0.349232  0.489923  0.004923      0.0    139\n",
       "140  0.349017  0.491898  0.004918      0.0    140\n",
       "141  0.348818  0.493281  0.004913      0.0    141\n",
       "\n",
       "[142 rows x 5 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# NeuralProphet\n",
    "np = NeuralProphet(growth=\"linear\", n_changepoints=10, changepoints_range=0.5)\n",
    "np.fit(df)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Seasonality\n",
    "\n",
    "In both frameworks, custom seasonality can be added using the `add_seasonality(...)` function.\n",
    "\n",
    "```python\n",
    "# Prophet\n",
    "p = Prophet(weekly_seasonality=False)\n",
    "p = p.add_seasonality(name=\"monthly\", period=30.5, fourier_order=5)\n",
    "p.fit(df)\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "fc6ff2357ab94fb6af9722ce0435f833",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Finding best initial lr:   0%|          | 0/236 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "9a6fd5729d2741ec8d2dca4049725b2b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Training: 0it [00:00, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MAE</th>\n",
       "      <th>RMSE</th>\n",
       "      <th>Loss</th>\n",
       "      <th>RegLoss</th>\n",
       "      <th>epoch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>6.970771</td>\n",
       "      <td>8.467905</td>\n",
       "      <td>0.840058</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>6.532929</td>\n",
       "      <td>7.965261</td>\n",
       "      <td>0.768197</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5.960650</td>\n",
       "      <td>7.304036</td>\n",
       "      <td>0.674393</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5.181200</td>\n",
       "      <td>6.403104</td>\n",
       "      <td>0.547921</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4.161289</td>\n",
       "      <td>5.167398</td>\n",
       "      <td>0.386437</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>0.368285</td>\n",
       "      <td>0.516671</td>\n",
       "      <td>0.005415</td>\n",
       "      <td>0.0</td>\n",
       "      <td>137</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>138</th>\n",
       "      <td>0.368621</td>\n",
       "      <td>0.514440</td>\n",
       "      <td>0.005426</td>\n",
       "      <td>0.0</td>\n",
       "      <td>138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>139</th>\n",
       "      <td>0.368627</td>\n",
       "      <td>0.515981</td>\n",
       "      <td>0.005387</td>\n",
       "      <td>0.0</td>\n",
       "      <td>139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>140</th>\n",
       "      <td>0.368233</td>\n",
       "      <td>0.512572</td>\n",
       "      <td>0.005382</td>\n",
       "      <td>0.0</td>\n",
       "      <td>140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>141</th>\n",
       "      <td>0.368327</td>\n",
       "      <td>0.514817</td>\n",
       "      <td>0.005379</td>\n",
       "      <td>0.0</td>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>142 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          MAE      RMSE      Loss  RegLoss  epoch\n",
       "0    6.970771  8.467905  0.840058      0.0      0\n",
       "1    6.532929  7.965261  0.768197      0.0      1\n",
       "2    5.960650  7.304036  0.674393      0.0      2\n",
       "3    5.181200  6.403104  0.547921      0.0      3\n",
       "4    4.161289  5.167398  0.386437      0.0      4\n",
       "..        ...       ...       ...      ...    ...\n",
       "137  0.368285  0.516671  0.005415      0.0    137\n",
       "138  0.368621  0.514440  0.005426      0.0    138\n",
       "139  0.368627  0.515981  0.005387      0.0    139\n",
       "140  0.368233  0.512572  0.005382      0.0    140\n",
       "141  0.368327  0.514817  0.005379      0.0    141\n",
       "\n",
       "[142 rows x 5 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# NeuralProphet\n",
    "np = NeuralProphet(weekly_seasonality=False)\n",
    "np = np.add_seasonality(name=\"monthly\", period=30.5, fourier_order=5)\n",
    "np.fit(df)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Country holidays\n",
    "\n",
    "The `add_country_holidays(...)` function works identical in both framework.\n",
    "\n",
    "```python\n",
    "# Prophet\n",
    "p = Prophet()\n",
    "p = p.add_country_holidays(country_name=\"US\")\n",
    "p.fit(df)\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e6e3b7f7377e4a0eb6262de376556e57",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Finding best initial lr:   0%|          | 0/236 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "eddd634da8b643dfbbdf5b58d203cc10",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Training: 0it [00:00, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MAE</th>\n",
       "      <th>RMSE</th>\n",
       "      <th>Loss</th>\n",
       "      <th>RegLoss</th>\n",
       "      <th>epoch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>6.797538</td>\n",
       "      <td>7.586237</td>\n",
       "      <td>0.799924</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>6.368385</td>\n",
       "      <td>7.140094</td>\n",
       "      <td>0.728214</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5.797359</td>\n",
       "      <td>6.531570</td>\n",
       "      <td>0.634331</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5.009449</td>\n",
       "      <td>5.698706</td>\n",
       "      <td>0.508090</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3.973015</td>\n",
       "      <td>4.581055</td>\n",
       "      <td>0.350154</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>0.343491</td>\n",
       "      <td>0.474378</td>\n",
       "      <td>0.004594</td>\n",
       "      <td>0.0</td>\n",
       "      <td>137</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>138</th>\n",
       "      <td>0.342121</td>\n",
       "      <td>0.475136</td>\n",
       "      <td>0.004579</td>\n",
       "      <td>0.0</td>\n",
       "      <td>138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>139</th>\n",
       "      <td>0.341720</td>\n",
       "      <td>0.476011</td>\n",
       "      <td>0.004581</td>\n",
       "      <td>0.0</td>\n",
       "      <td>139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>140</th>\n",
       "      <td>0.341734</td>\n",
       "      <td>0.476153</td>\n",
       "      <td>0.004584</td>\n",
       "      <td>0.0</td>\n",
       "      <td>140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>141</th>\n",
       "      <td>0.341740</td>\n",
       "      <td>0.476323</td>\n",
       "      <td>0.004578</td>\n",
       "      <td>0.0</td>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>142 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          MAE      RMSE      Loss  RegLoss  epoch\n",
       "0    6.797538  7.586237  0.799924      0.0      0\n",
       "1    6.368385  7.140094  0.728214      0.0      1\n",
       "2    5.797359  6.531570  0.634331      0.0      2\n",
       "3    5.009449  5.698706  0.508090      0.0      3\n",
       "4    3.973015  4.581055  0.350154      0.0      4\n",
       "..        ...       ...       ...      ...    ...\n",
       "137  0.343491  0.474378  0.004594      0.0    137\n",
       "138  0.342121  0.475136  0.004579      0.0    138\n",
       "139  0.341720  0.476011  0.004581      0.0    139\n",
       "140  0.341734  0.476153  0.004584      0.0    140\n",
       "141  0.341740  0.476323  0.004578      0.0    141\n",
       "\n",
       "[142 rows x 5 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# NeuralProphet\n",
    "np = NeuralProphet()\n",
    "np = np.add_country_holidays(country_name=\"US\")\n",
    "np.fit(df)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Future regressors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def nfl_sunday(ds):\n",
    "    date = pd.to_datetime(ds)\n",
    "    if date.weekday() == 6 and (date.month > 8 or date.month < 2):\n",
    "        return 1\n",
    "    else:\n",
    "        return 0\n",
    "\n",
    "\n",
    "df_nfl = df.copy()\n",
    "df_nfl[\"nfl_sunday\"] = df_nfl[\"ds\"].apply(nfl_sunday)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```python\n",
    "# Prophet\n",
    "p = Prophet()\n",
    "p = p.add_regressor(\"nfl_sunday\")\n",
    "p.fit(df_nfl)\n",
    "future_p = p.make_future_dataframe(periods=30)\n",
    "future_p[\"nfl_sunday\"] = future_p[\"ds\"].apply(nfl_sunday)\n",
    "_ = p.predict(future_p)\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1f021306fe984eb78355b0304393cf5c",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Finding best initial lr:   0%|          | 0/236 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e554a92116a94d67b0d5ba257d811ff9",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Training: 0it [00:00, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2722c67fbcc949329f251aee73c995f9",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Predicting: 91it [00:00, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# NeuralProphet\n",
    "np = NeuralProphet()\n",
    "future_np = np.make_future_dataframe(df_nfl, periods=30)\n",
    "np = np.add_future_regressor(\"nfl_sunday\")\n",
    "np.fit(df_nfl)\n",
    "future_np[\"nfl_sunday\"] = future_np[\"ds\"].apply(nfl_sunday)\n",
    "_ = np.predict(future_np)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Holidays & Events\n",
    "\n",
    "What is referred to as \"holidays\" in Prophet is named \"events\" more generically in NeuralProphet. In Prophet, holidays are passed during the init of the Prophet forecaster. In NeuralProphet, they are added using the `add_events(...)` function.\n",
    "\n",
    "```python\n",
    "# Prophet\n",
    "superbowl_p = pd.DataFrame(\n",
    "    {\n",
    "        \"holiday\": \"superbowl\",\n",
    "        \"ds\": pd.to_datetime([\"2010-02-07\", \"2014-02-02\", \"2016-02-07\"]),\n",
    "        \"lower_window\": 0,\n",
    "        \"upper_window\": 1,\n",
    "    }\n",
    ")\n",
    "\n",
    "p = Prophet(holidays=superbowl_p)\n",
    "p = p.fit(df)\n",
    "future_p = p.make_future_dataframe(periods=30)\n",
    "forecast_p = p.predict(future_p)\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f80ef7fe46a7484e8ff7aeafdbfd7fbb",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Finding best initial lr:   0%|          | 0/236 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8eb5c4d1c994410389100269dc35c39d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Training: 0it [00:00, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e18a62c008be49859ddc702f140344b5",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Predicting: 91it [00:00, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# NeuralProphet\n",
    "superbowl_np = pd.DataFrame(\n",
    "    {\n",
    "        \"event\": \"superbowl\",\n",
    "        \"ds\": pd.to_datetime([\"2010-02-07\", \"2014-02-02\", \"2016-02-07\"]),\n",
    "    }\n",
    ")\n",
    "\n",
    "np = NeuralProphet()\n",
    "np = np.add_events(\"superbowl\", lower_window=0, upper_window=1)\n",
    "history_df = np.create_df_with_events(df, superbowl_np)\n",
    "_ = np.fit(history_df)\n",
    "future_np = np.make_future_dataframe(history_df, events_df=superbowl_np, periods=30)\n",
    "forecast_np = np.predict(future_np)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Regularization\n",
    "\n",
    "In Prophet, the argument `prior_scale` can be used to configure regularization. In NeuralProphet, regularization is controlled via the `reg` argument. `prior_scale` and `reg` have an inverse relationship and therefore cannot directly be translated.\n",
    "\n",
    "```python\n",
    "# Prophet\n",
    "from prophet import Prophet\n",
    "\n",
    "p = Prophet(seasonality_prior_scale=0.5)\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# NeuralProphet\n",
    "from neuralprophet import NeuralProphet\n",
    "\n",
    "np = NeuralProphet(seasonality_reg=0.1)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Uncertainty\n",
    "\n",
    "In Prophet, all forecasts are configured to use uncertainty intervals automatically. In NeuralProphet, the uncertaintly intervals need to be configured by the user. TorchProphet uses the default uncertainty intervals as defined in Prophet to mirror the behviour.\n",
    "\n",
    "However, the uncertainty interval calculation differs between Prophet and NeuralProphet. Since Prophet uses a MAP estimate for uncertainty by default [Thread](https://github.com/facebook/prophet/issues/1124), NeuralProphet relies on quantile regression. Thus, the values are not directly comparable.\n",
    "\n",
    "```python\n",
    "# Prophet\n",
    "p = Prophet(interval_width=0.80)\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# NeuralProphet\n",
    "np = NeuralProphet(quantiles=[0.90, 0.10])"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Unsupported features in TorchProphet\n",
    "- **Saturating forecasts**  \n",
    "  Saturating forecasts limit the predicted value to a certain limit called capacity. In Prophet, this is archieved by passing the `growth='logistic'` argument during initialization and providing a capacity limit. This functionality is currently not supported by NeuralProphet.\n",
    "- **Conditional seasonality**  \n",
    "  Conditional seasonality allows to model certain events as seasonal effects (eg. whether it's currently NFL season). This can be archieved in Prophet by passing the argument `condition_name` to `add_seasonality(...)`. This feature is currently also not supported in NeuralProphet.\n",
    "\n",
    "### Additional features of TorchProphet\n",
    "- **Autoregression**  \n",
    "  TorchProphet allows to model autoregression of arbitrary lag lengths by building on a Neural Network implementation of the autoregression algorithm (called AR-Net). More information can be found here [Autoregression](https://neuralprophet.com/html/autoregression_yosemite_temps.html).\n",
    "- **Lagged regressors**  \n",
    "  TorchProphet does not only support \"future\" regressors like in Prophet, but also lagged regressors that are simultaneous to the time series to predict. More information can be found here [Lagged covariates](https://neuralprophet.com/html/lagged_covariates_energy_ercot.html).\n",
    "- **Global model**  \n",
    "  TorchProphet supports hierachical forecasts by training a global model on many simultaneous time series that is used to improve the performance of predicting an individual time series. More infos can be found here [Global Model](https://neuralprophet.com/html/global_modeling.html).\n",
    "- **Neural Network architecture**  \n",
    "  TorchProphet models the forecast components using a Neural Network. By default, the network has no hidden layers. However, for more complex time series, the depth of the network can be increased to learn more complex relations.\n",
    "- **PyTorch**  \n",
    "  TorchProphet is build on Pytorch (soon PyTorch Lightning) and thus provides interfaces for developers to extend the vanilla model for specific use cases.\n",
    "- **Flexible multiplicativity**  \n",
    "  Multiplicativity of future regressors and seasonality can be set separately.\n",
    "  "
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.9 ('venv': venv)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.16"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "e488e6bd15b38f84fe669bfc536f96b6c5fb6be3ab1c1213873b81c0afcbd577"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
